﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NP.BL;

namespace ConsoleApplication1
{
    class Methods
    {
        public static void DisplayEmployeesSummary(IEnumerable<EmployeeSummaryViewModel> e)
        {
            int[] l = { 
                          e.Max(n => n.Id.ToString().Length), 
                          e.Max(n => n.FN.ToString().Length),
                          e.Max(n => n.LN.ToString().Length),
                          e.Max(n => n.TotalSold.ToString().Length)
                      };

            int m = l.Length + 1;
            int k = 1;
            StringBuilder sb = new StringBuilder();

            foreach (var i in e)
            {
                sb.Append('-', l.Sum()+m);
                sb.AppendLine();
                sb.AppendFormat("|{0,-" + l[0] + "}|", i.Id);
                sb.AppendFormat("{0,-" + l[1] + "}|", i.FN);
                sb.AppendFormat("{0,-" + l[2] + "}|", i.LN);
                sb.AppendFormat("{0,-" + l[3] + "}|", i.TotalSold);
                sb.AppendLine();
                sb.Append("|");
                foreach (var j in i.CityList)
                {
                    if (k == i.CityList.Length)
                        sb.Append(j.ToString());
                    else
                    { sb.Append(j.ToString() + ","); }
                    k++;
                }
                k = 1;
                sb.Append("|");
                sb.AppendLine();
            }
            sb.Append('-', l.Sum() + m);
            sb.AppendLine();
            Console.Write(sb.ToString());
        }

        public static void DisplayCustomersSummary(CustumerSummaryViewModel[] c)
        {
            int[] l = { 
                          c.Max(n => n.CustomerID.ToString().Length), 
                          c.Max(n => n.CunstomerName.ToString().Length),
                          c.Max(n => n.TotalPurchases.ToString().Length),
                          c.Max(n => n.Type.ToString().Length)
                      };

            int m = l.Length + 1;

            StringBuilder sb = new StringBuilder();

            foreach (var i in c)
            {
                sb.Append('-', l.Sum()+m);
                sb.AppendLine();
                sb.AppendFormat("|{0,-" + l[0] + "}|", i.CustomerID);
                sb.AppendFormat("{0,-" + l[1] + "}|", i.CunstomerName);
                sb.AppendFormat("{0,-" + l[2] + "}|", i.TotalPurchases);
                sb.AppendFormat("{0,-" + l[3] + "}|", i.Type);
                sb.AppendLine();
            }
            sb.Append('-', l.Sum() + m);
            sb.AppendLine();
            Console.Write(sb.ToString());
        }

        public static void DisplayProductsTopDiscounts(ProductTopDiscountViewModel[] p)
        {
            int[] l = { 
                          p.Max(n => n.ProductID.ToString().Length), 
                          p.Max(n => n.Product.ToString().Length),
                          p.Max(n => n.Quantity.ToString().Length),
                          p.Max(n => n.UnitPrice.ToString().Length),
                          p.Max(n => n.Discout.ToString().Length),
                          p.Max(n => n.TotalDiscout.ToString().Length)
                      };

            int m = l.Length + 1;

            StringBuilder sb = new StringBuilder();

            foreach (var i in p)
            {
                sb.Append('-', l.Sum() + m);
                sb.AppendLine();
                sb.AppendFormat("|{0,-" + l[0] + "}|", i.ProductID);
                sb.AppendFormat("{0,-" + l[1] + "}|", i.Product);
                sb.AppendFormat("{0,-" + l[2] + "}|", i.Quantity);
                sb.AppendFormat("{0,-" + l[3] + "}|", i.UnitPrice);
                sb.AppendFormat("{0,-" + l[4] + "}|", i.Discout);
                sb.AppendFormat("{0,-" + l[5] + "}|", i.TotalDiscout);
                sb.AppendLine();
            }
            sb.Append('-', l.Sum() + m);
            sb.AppendLine();
            Console.Write(sb.ToString());
        }

        public static void DisplayTotalProductsSold(TotalProductSoldViewModel[] p)
        {
            int[] l = { 
                          p.Max(n => n.ProductID.ToString().Length), 
                          p.Max(n => n.Product.ToString().Length),
                          p.Max(n => n.TotalSold.ToString().Length),
                      };

            int m = l.Length + 1;

            StringBuilder sb = new StringBuilder();

            foreach (var i in p)
            {
                sb.Append('-', l.Sum() + m);
                sb.AppendLine();
                sb.AppendFormat("|{0,-" + l[0] + "}|", i.ProductID);
                sb.AppendFormat("{0,-" + l[1] + "}|", i.Product);
                sb.AppendFormat("{0,-" + l[2] + "}|", i.TotalSold);
                sb.AppendLine();
            }
            sb.Append('-', l.Sum() + m);
            sb.AppendLine();
            Console.Write(sb.ToString());
        }

        public static void DisplayUnitsInStock(UnitsInStockViewModel[] p)
        {
            int[] l = { 
                          p.Max(n => n.ProductID.ToString().Length), 
                          p.Max(n => n.ProductName.ToString().Length),
                          p.Max(n => n.SupplierName.ToString().Length),
                          p.Max(n => n.UnitsInStock.ToString().Length),
                      };

            int m = l.Length + 1;

            StringBuilder sb = new StringBuilder();

            foreach (var i in p)
            {
                sb.Append('-', l.Sum() + m);
                //sb.AppendLine();
                sb.AppendFormat("|{0,-" + l[0] + "}|", i.ProductID);
                sb.AppendFormat("{0,-" + l[1] + "}|", i.ProductName);
                sb.AppendFormat("{0,-" + l[2] + "}|", i.SupplierName);
                sb.AppendFormat("{0,-" + l[3] + "}|", i.UnitsInStock);
                //sb.AppendLine();
            }
            sb.Append('-', l.Sum() + m);
            sb.AppendLine();
            Console.Write(sb.ToString());
        }
    }
}